package com.atguigu.yygh.hosp.controller.user;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import io.swagger.annotations.ApiOperation;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user/hosp/schedule")
public class UserScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation("根据排班Id获取排班信息(远程调用)")
    @GetMapping("/{scheduleId}")
    public ScheduleOrderVo getScheduleById(@PathVariable String scheduleId){

        return  scheduleService.getScheduleById(scheduleId);
    }

    @ApiOperation("根据排班Id获取排班信息")
    @GetMapping("/info/{scheduleId}")
    public R getScheduleId(@PathVariable("scheduleId") String scheduleId){
        Schedule schedule=  scheduleService.getScheduleInfo(scheduleId);
        return R.ok().data("schedule",schedule);
    }

    @ApiOperation("获取医院排班信息(分页)")
    @GetMapping("/{hoscode}/{depcode}/{pageNum}/{pageSize}")
    public R getSchedulePage(@PathVariable("hoscode") String hoscode,
                             @PathVariable("depcode") String depcode,
                             @PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize){
//      根据查询条件获取排班信息
        Map<String,Object> map = scheduleService.getSchedulePageByCondition(hoscode,depcode,pageNum,pageSize);
        return R.ok().data(map);
    }

    @ApiOperation("查询医院的详情信息")
    @GetMapping("/{hoscode}/{depcode}/{workdate}")
    public R getScheduleDetail(@PathVariable String hoscode,
                               @PathVariable String depcode,
                               @PathVariable String workdate){
//        字符串类型转换为Date类型
        Date date = new DateTime(workdate).toDate();
        List<Schedule> details = scheduleService.detail(hoscode, depcode, date);
        return R.ok().data("details",details);
    }
}
